package com.gbiac.modules.monitor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gbiac.modules.monitor.entity.Seat;
import com.gbiac.modules.monitor.mapper.SeatMapper;
import com.gbiac.modules.monitor.service.ISeatService;
import org.jeecg.common.exception.JeecgBootException;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Description: 席位管理
 * @Author: jeecg-boot
 * @Date:   2024-11-30
 * @Version: V1.0
 */
@Service
public class SeatServiceImpl extends ServiceImpl<SeatMapper, Seat> implements ISeatService {

    @Override
    public void enableSeat(String seatId) {
        Seat seat = getById(seatId);
        if (seat == null) {
            throw new JeecgBootException("找不到席位");
        }
        if ("1".equals(seat.getDisable())) {
            seat.setDisable("0");
            updateById(seat);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void enableSeatAll(String orgCode) {
        List<Seat> seatList = list(new LambdaQueryWrapper<Seat>().eq(Seat::getOrgCode, orgCode));
        for (Seat seat : seatList) {
            enableSeat(seat.getId());
        }
    }
}
